package sort;

/**
 * @author LQQ
 * @version V1.0
 * @Package PACKAGE_NAME
 * @date 2020/10/11 16:09
 * @Description
 */
public class SelectionSort {
    public static int[] selectionSort(int[] array) {
        if (array.length == 0) return array;
        for (int i = 0; i < array.length; i++) {
            int min = i;
            for (int j = i; j < array.length; j++) {
                if (array[min] > array[j]) {
                    min = j;
                }
            }
            if(min!=i){
                int temp = array[min];
                array[min] = array[i];
                array[i] = temp;
            }
        }
        return array;
    }

    public static void main(String[] args) {
        int[] array = new int[]{11, 1, 3, 1, 4, 7, 45, 76, 23, 7, 34, 9, 90, 0};
        array = selectionSort(array);
        for (int num : array) {
            System.out.println(num);
        }
    }
}
